package data;

public class ConversationRecorder {

	private Message[] conversation;
	private int insertIdx;
	private final int size;

	public ConversationRecorder(int size){
		conversation = new Message[size];
		this.size = size;
		insertIdx = 0;
	}

	public boolean addMessage(String user, String message){
		if(insertIdx < size)
			conversation[insertIdx++] = new Message(user, message);
		else{
			for(int i = 0; i<size-1; ++i)
				conversation[i].set(conversation[i+1].getUser(), conversation[i+1].getMessage());
			conversation[size-1].set(user, message);
		}
		return true;
	}

	public Message[] getConversation(){
		return conversation;
	}
	
	public void reset(){
		for(int i = 0; i<size; ++i)
			conversation[i] = null;
	}
}
